package edu.llg.meta;

import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.json.JSONUtil;

/**
 * @author 隆利果
 * @version springboot-init-meta.0
 * @date 2024/2/24 14:41
 */
public class MetaManager {

    private static volatile Meta meta;

    private MetaManager() {
    }

    /**
     * 双检锁单例
     * @return
     */
    public static Meta getMeta() {
        if(meta == null){
            synchronized (MetaManager.class) {
                if(meta == null){
                    meta = init();
                }
            }
        }
        return meta;
    }

    private static Meta init(){
        String json = ResourceUtil.readUtf8Str("examples/springboot-init/springboot-init-meta.json");
        Meta bean = JSONUtil.toBean(json, Meta.class);
        MetaValidator.doValidAndFill(bean);
        return bean;
    }
}
